#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 2e5+10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define sd(n) scanf("%d",&n)
#define sld(n) scanf("%lld",&n)
#define pd(n) printf("%d", (n))
#define pld(n) printf("%lld", n)

//----------------------------------------------------------------------------//
int n;
char a[100010];
int p1[100010];
int p2[100010];
//int sum[100010];
char s, e, tt;
ll ans = 0;
int main()
{
    sd(n);
    tt = getchar();
    scanf("%c", &s);
    tt = getchar();
    scanf("%c", &e);
    tt = getchar();

    scanf("%s", a);
    int cnt1 = 0;
    int cnt2 = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i] == s)
        {
            p1[++cnt1] = i + 1;
        }
        if (a[i] == e)
        {
            p2[++cnt2] = i + 1;
        }
    }
    if (cnt1 == 0 || cnt2 == 0)
    {
        pd(0);
        return 0;
    }

    for (int i = 1; i <= cnt1; i++)
    {
        for (int j = cnt2; j >= 1; j--)
        {
            if (p1[i] > p2[j]) break;
            else ans++;
        }
    }

    pld(ans);

    return 0;
}




//合理利用getchar刷新
sd(n);
tt = getchar();
scanf("%c", &s);
tt = getchar();
scanf("%c", &e);
tt = getchar();

scanf("%s", a);